package goclient

import (
	"bytes"
)

type ReadCloser interface {
	Read(p []byte) (int, error)
	Close() error
}

type Writer interface {
	Write(p []byte) (int, error)
}

type ReadWriter interface {
	Read(p []byte) (int, error)
	Write(p []byte) (int, error)
}

type nopCloser struct {
	reader *bytes.Reader
}

func (c *nopCloser) Read(p []byte) (int, error) {
	return c.reader.Read(p)
}

func (c *nopCloser) Close() error {
	return nil
}

func BytesToReadCloser(data []byte) ReadCloser {
	return &nopCloser{reader: bytes.NewReader(data)}
}

func StringToReadCloser(data string) ReadCloser {
	return &nopCloser{reader: bytes.NewReader([]byte(data))}
}
